from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
from .image_button import ImageButton

class JobMenuItem(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)
#
#		background - blank menu item
#
		bg = QtGui.QLabel(self)
		path = "resources/menu_blank.png"
		bg.setPixmap(QtGui.QPixmap(path))

		self.caption = QtGui.QLabel(self)
		self.caption.setGeometry(7, 5, 70, 23)
#
#		centered and transparent background
#
		self.caption.setStyleSheet("background-color: transparent;")
		self.caption.setAlignment(Qt.AlignVCenter|Qt.AlignHCenter)
#
#		set the font
#
		font = QtGui.QFont("Times New Roman", 14)
		self.caption.setFont(font)

		self.glow = QtGui.QLabel(self)
		path = "resources/menu_glow.png"
		self.glow.setPixmap(QtGui.QPixmap(path))
		self.glow.move(2,0)
		self.glow.hide()



	def enterEvent(self, e):
		self.glow.show()

	def leaveEvent(self, event):
		self.glow.hide()

	clicked = QtCore.pyqtSignal(object)
	def mousePressEvent(self, e):
		self.clicked.emit(self)

#
#	set the label on the menu item
#
	def set_text(self, s):
		self.caption.setText(s)


	def text(self):
		return self.caption.text()

class JobMenuDismissBar(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bar = QtGui.QLabel(self)
		path = "resources/menu_dismiss_bar.png"
		bar.setPixmap(QtGui.QPixmap(path))
		bar.setGeometry(0, 7,91,18)

		self.dismiss = ImageButton("dismiss", self,
			"resources/menu_dismiss.png",
			"resources/menu_dismiss_h.png",
			"resources/menu_dismiss_d.png",
			"resources/menu_disiss.png",
		)
		self.dismiss.setGeometry(31,0, 30,31)
		self.dismiss.clicked.connect(self.banish)

	banish = QtCore.pyqtSignal()


#
# job menu widget
#
class JobMenu(QtGui.QWidget):
	banish = QtCore.pyqtSignal()
#
#	let's have a list of jobs.
#
#	we'll filter these by girl and circumstance eventually
#	but for now, let's just have some captions
#
#	these need to be Job instances from data.jobs as well
#
	jobs = [
		"Sleep",	"Rest",		"Whoring",	"Streets",
		"Assistant",	"Follow",	"Cleaning",	"Cabaret",
		"Training"
	]
	clicked = QtCore.pyqtSignal(object)

#
#	set this sucker up!
#
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)
		self.setGeometry(0,0,101,642)
#
#		draw the rails
#
		bg = QtGui.QLabel(self)
		path = "resources/menu_rails.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.setGeometry(0,0,101,642)


		dismiss = JobMenuDismissBar(self)
		dismiss.move(3,177)
		dismiss.banish.connect(self.banish)

		self.cells = []
#
#		y-offset for the bottom cell
#
		y = 584
#
#		loop over the cells
#
		for i in range(9):
#
#			create a cell
#
			cell = JobMenuItem(self)
#
#			set the level, decrement by cell height + 3 pix margin
#
			cell.level = y
			y -= 36
#
#			move it off the top, set the label 
#			and add the cell to the list
#
			#cell.move(6,y - 500)
			cell.move(6,y )
			cell.set_text(self.jobs[i])
			cell.clicked.connect(self.clicked)
			self.cells.append(cell)

if __name__ == "__main__":
	import sys
	from collections import namedtuple

#
#	create the app
#
	app = QtGui.QApplication(sys.argv)

#
#	use the wallpaper as the top level widget
#
	top = QtGui.QLabel()
	top.setGeometry(0, 0, 1024, 768)
	path = "resources/wood.jpg"
	top.setPixmap(QtGui.QPixmap(path))

	def wow():
		print "WOW"

	jm = JobMenu(top)
	jm.move(-100,-100)
	jm.banish.connect(wow)

	pa = QtCore.QPropertyAnimation(jm, "geometry")
	pa.setDuration(400)
	pa.setStartValue(QtCore.QRect(100, -100, 101, 642))
	pa.setEndValue(QtCore.QRect(600, -100, 101, 642))
	pa.setEasingCurve(QtCore.QEasingCurve.OutBack)
	pa.start()


	top.show()
	sys.exit(app.exec_())
